package math;

import java.awt.geom.Point2D;

public class Equations 
{
	/**
	 * 
	 * @param num1 the first known number
	 * @param num2 the second known number
	 * @param solveFor the value to solve for (A, B, or C)
	 * @return the result
	 */
	public static double pythagorean(double num1, double num2, char solveFor)
	{
		if (solveFor == 'A' || solveFor == 'B')
		{
			double c = Math.max(num1, num2);
			double side = Math.min(num1, num2);
			return Math.sqrt(Math.pow(c, 2) - Math.pow(side, 2));
		}
		else if (solveFor == 'C')
		{
			return Math.sqrt(Math.pow(num1, 2) + Math.pow(num2, 2));
		}
		else
		{
			throw new IllegalArgumentException("solveFor must be A, B, or C.");
		}
	}
	/**
	 * 
	 * @param angle the angle to be normalized
	 * @return the inputted angle will be between 0 and 2pi after being normalized
	 */
	public static double normalizeAngle(double angle)
	{
		if(angle > 2*Math.PI)
			angle = angle % (2*Math.PI);
		if(angle < 0)
			angle = 2*Math.PI + angle % (2*Math.PI);
		return angle;
	}
	/**
	 * 
	 * @param p1 the first point
	 * @param p2 the second point
	 * @return the angle from the x axis of point one to point two
	 */
	public static double pointToPointAngle(Point2D p1, Point2D p2)
	{
		double x = p2.getX() - p1.getX();
		double y = p2.getY() - p1.getY();
		return Math.atan2(y, x);
	}
}
